1 //------------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // Implements the connection to PHDLL (PresentationHostDLL.dll v3 or PresentationHost_vX.dll for v4+).
12 // Ported Windows->DevDiv. See SourcesHistory.txt.
14 //------------------------------------------------------------------------
16 #include "PreCompiled.hxx"
17 #include "Version.hxx"
18 #include "ActivationContext.hxx"
21 CVersion::CVersion(__in_ecount(1) LPCWSTR pswzVersion
):
22 m_hInstance(0), m_bIsValid(false), m_bIsAttached(false),
23 m_dwMajor(0), m_dwMinor(0), m_dwBuild(0),
24 m_pfnActivate(0), m_pfnDeactivate(0), m_pfnForwardTranslateAccelerator(0),
25 m_pfnSaveToHistory(0), m_pfnLoadFromHistory(0)
29 SetValue(pswzVersion
);
30 ParseVersion(pswzVersion
);
34 int CVersion::CompareTo(__in_ecount(1) CVersion
* pOther
)
36 int nResult
= this->m_dwMajor
- pOther
->m_dwMajor
;
40 nResult
= this->m_dwMinor
- pOther
->m_dwMinor
;
45 nResult
= this->m_dwBuild
- pOther
->m_dwBuild
;
51 HRESULT
CVersion::Attach()
53 EventWriteWpfHostUm_VersionAttach();
55 if(m_bIsValid
&& GetLibraryPath() != NULL
)
57 m_hInstance
= LoadLibrary(GetLibraryPath());
59 if(m_hInstance
!= NULL
)
61 m_pfnActivate
= (ActivatePfn
) GetProcAddress(m_hInstance
, "Activate");
62 m_pfnDeactivate
= (DeactivatePfn
) GetProcAddress(m_hInstance
, "Deactivate");
63 m_pfnForwardTranslateAccelerator
= (ForwardTranslateAcceleratorPfn
) GetProcAddress(m_hInstance
, "ForwardTranslateAccelerator");
64 m_pfnSaveToHistory
= (SaveToHistoryPfn
) GetProcAddress(m_hInstance
, "SaveToHistory");
65 m_pfnLoadFromHistory
= (LoadFromHistoryPfn
) GetProcAddress(m_hInstance
, "LoadFromHistory");
70 m_pfnForwardTranslateAccelerator
&&
74 // Dev10.582711 - CRT initialization for PresentationCore v3 fails when hosted by PresentationHost v4.
75 // This is an involved issue, with a history going back to v3.5 SP1.
76 // See \\ddindex2\sources2\orc----p\wpf\src\core\crtinit.cpp for the initial issue and hacky
77 // workaround and the above bug for the unfortunate flaw that cropped up in v4.
78 // The essence of the patch here is that we apply a Fusion activation context for loading the VC 8 CRT
79 // based on the manifest embedded in PHDLL v3, which is the same as what PresentationCore.dll has
80 // (as long as they are the same build flavor--this was a caveat about the original workaround too).
81 // This activation context needs to be active only when PresentationCore (v3) is doing its
82 // initialization and binding to msvcr80.dll, but it doesn't hurt to keep it active for the whole
83 // lifetime of the process. In some sense this gives v3 a more compatible runtime environment
84 // because PH v3 used to have that manifest reference to the VC 8 CRT.
87 ActivationContext actctx
;
88 if(!actctx
.Create(GetLibraryPath()) || !actctx
.Activate(false))
96 return m_bIsAttached
? S_OK
: E_FAIL
;
99 void CVersion::ParseVersion(__in_ecount(1) LPCWSTR pswzVersion
)
101 DWORD dwNumber
[3] = {0,0,0};
102 // nIndex is used in a loop bounded by a constant (3). Since it is safely bounded we can declare it as __bound to avoid PREFast warnings
103 __bound UINT nIndex
= 0;
107 BOOL bGotOpenQuote
= FALSE
;
109 WCHAR
* pwcNext
= (WCHAR
*)pswzVersion
;
111 // Initial quote is allowed and ignored
112 if (*pwcNext
== L
'\"')
115 bGotOpenQuote
= TRUE
;
118 // Intial "v" is allowed, and ignored
119 if (*pwcNext
== 'v' || *pwcNext
== 'V')
124 while (*pwcNext
&& nIndex
< 3)
130 else if (iswdigit(*pwcNext
))
132 dwNumber
[nIndex
] *= 10;
133 dwNumber
[nIndex
] += *pwcNext
- '0';
137 // Close quote (if it is the last character) is allowed and ignored
138 if (bGotOpenQuote
&& *pwcNext
== L
'\"')
158 m_dwMajor
= dwNumber
[0];
159 m_dwMinor
= dwNumber
[1];
160 m_dwBuild
= dwNumber
[2];
170 void CVersion::Activate(__in_ecount(1) const ActivateParameters
* pParameters
, __deref_out_ecount(1) LPUNKNOWN
* ppInner
)
172 EventWriteWpfHostUm_VersionActivateStart();
174 m_pfnActivate(pParameters
, ppInner
); //[supposed to invoke Watson on failure]
176 EventWriteWpfHostUm_VersionActivateEnd();
179 void CVersion::Deactivate()
184 HRESULT
CVersion::ForwardTranslateAccelerator(__in_ecount(1) MSG
* pMsg
)
186 return m_pfnForwardTranslateAccelerator(pMsg
, VARIANT_FALSE
/*the app wasn't given a chance*/);
189 HRESULT
CVersion::SaveToHistory(__in_ecount(1) IStream
* pHistoryStream
)
191 return m_pfnSaveToHistory(pHistoryStream
);
194 HRESULT
CVersion::LoadFromHistory(__in_ecount(1) IStream
* pHistoryStream
, __in_ecount(1) IBindCtx
* pBindCtx
)
196 return m_pfnLoadFromHistory(pHistoryStream
, pBindCtx
);